package com.hncc.dms.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hncc.bms.domain.BmsInvoiceRecord;
import com.hncc.dms.service.IBmsInvoiceRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;

/**
 * 发票Controller
 * 
 * @author ruoyi
 * @date 2020-09-04
 */
@RestController
@RequestMapping("/bms/invoice_record")
@Api(tags = "发票接口")
public class BmsInvoiceRecordController extends BaseController
{
    @Resource
    private IBmsInvoiceRecordService bmsInvoiceRecordService;

    /**
     * 查询发票列表
     */
    @ApiOperation(value = "条件分页查询发票",httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('bms:invoice_record:list')")
    @GetMapping("/list")
    public TableDataInfo list(BmsInvoiceRecord bmsInvoiceRecord)
    {
        startPage();
        List<BmsInvoiceRecord> list = bmsInvoiceRecordService.selectBmsInvoiceRecordList(bmsInvoiceRecord);
        return getDataTable(list);
    }

    /**
     * 导出发票列表
     */
    @PreAuthorize("@ss.hasPermi('bms:invoice_record:export')")
    @Log(title = "发票", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BmsInvoiceRecord bmsInvoiceRecord)
    {
        List<BmsInvoiceRecord> list = bmsInvoiceRecordService.selectBmsInvoiceRecordList(bmsInvoiceRecord);
        ExcelUtil<BmsInvoiceRecord> util = new ExcelUtil<BmsInvoiceRecord>(BmsInvoiceRecord.class);
        return util.exportExcel(list, "invoice_record");
    }

    /**
     * 获取发票详细信息
     */
    @ApiOperation(value = "根据id获取发票详细信息",httpMethod = "GET",
            notes = "根据id查询发票")
    @ApiImplicitParam(paramType = "path",name = "id",value = "发票id",dataType = "Long",required = true)
    @PreAuthorize("@ss.hasPermi('bms:invoice_record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bmsInvoiceRecordService.selectBmsInvoiceRecordById(id));
    }

    /**
     * 新增发票
     */
    @ApiOperation(value = "新增",httpMethod = "POST", notes = "新增发票")
    @ApiImplicitParam(name = "bmsInvoiceRecord", value = "新增发票", dataType = "BmsInvoiceRecord")
    @PreAuthorize("@ss.hasPermi('bms:invoice_record:add')")
    @Log(title = "发票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BmsInvoiceRecord bmsInvoiceRecord)
    {
        return toAjax(bmsInvoiceRecordService.insertBmsInvoiceRecord(bmsInvoiceRecord));
    }

    /**
     * 修改发票
     */
    @ApiOperation(value = "修改", httpMethod = "PUT", notes = "修改发票")
    @ApiImplicitParam(name = "bmsInvoiceRecord", value = "修改发票", dataType = "BmsInvoiceRecord")
    @PreAuthorize("@ss.hasPermi('bms:invoice_record:edit')")
    @Log(title = "发票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmsInvoiceRecord bmsInvoiceRecord)
    {
        return toAjax(bmsInvoiceRecordService.updateBmsInvoiceRecord(bmsInvoiceRecord));
    }

    /**
     * 删除发票
     */
    @ApiOperation(value = "批量删除", httpMethod = "DELETE", notes = "根据ids删除发票")
    @ApiImplicitParam(paramType = "path",name = "ids",value = "发票id",dataType = "Long[]",required = true)
    @PreAuthorize("@ss.hasPermi('bms:invoice_record:remove')")
    @Log(title = "发票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bmsInvoiceRecordService.deleteBmsInvoiceRecordByIds(ids));
    }

    /**
     * 根据挂号id获取发票编号及id
     * @param registrationId
     * @return
     */
    @GetMapping("/getInvoiceNoByRegistrationId/{registrationId}")
    public AjaxResult getInvoiceNoByRegistrationId(@PathVariable String registrationId){
        return AjaxResult.success(bmsInvoiceRecordService.getInvoiceNoByRegistrationId(Long.parseLong(registrationId)));
    }
}
